<?php
/* *
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2019 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
*/
class admin_chat_log_controller extends adminCommon{  
	function index_action(){
		$chatM=$this->MODEL('chat');
		
		if($_GET['keyword']){
			
			$keyword	=	trim($_GET['keyword']);
			
			$type		=	intval($_GET['type']);
			
			if ($type=='1'){
				
				$where['fname']		=	array('like',$keyword);
			}else if($type=='2'){
				
				$where['tname']		=	array('like',$keyword);
			}elseif($type=='3'){
				
				$where['content']	=	array('like',$keyword);
			}
			$urlarr['type']			=	"".$type."";
			
			$urlarr['keyword']		=	"".$keyword."";
		}
		if(($_GET['date'])){
			
			$times=@explode('~',$_GET['date']);
			
			$where['sendTime']	=	array('>=',strtotime($times[0]." 00:00:00")*1000);
			
			$where['sendTime']	=	array('<',strtotime($times[1]." 23:59:59")*1000);
			
			$urlarr['date']		=	$_GET['date'];
		}
		
		$urlarr['page']	=	"{{page}}";
		
		$pageurl		=	Url($_GET['m'],$urlarr,'admin');
		
		$pageM			=	$this  -> MODEL('page');
		
		$pages			=	$pageM -> pageList('chat_log',$where,$pageurl,$_GET['page']);
		
		//分页数大于0的情况下 执行列表查询
		
		if($pages['total'] > 0){
			
			if($_GET['order'])
			{
				$where['orderby']	=	$_GET['t'].','.$_GET['order'];
				
				$urlarr['order']	=	$_GET['order'];
				
				$urlarr['t']		=	$_GET['t'];
			}else{
				
				$where['orderby']	=	'id';
			}
			
			$where['limit']	=	$pages['limit'];
		
			$chatList		=	$chatM -> getChatLogList($where);
			
			if ($chatList && is_array($chatList)){
				
				foreach ($chatList as $k=>$v){
					
					$chatList[$k]['sendTime'] = ceil($v['sendTime']/1000);
				}
			}
		}
		
		$this->yunset('rows',$chatList);
		
		$this->yuntpl(array('admin/admin_chat_log'));
	}
	function del_action(){
		
		$chatM	=	$this -> Model('chat');
		
		if(is_array($_POST['del'])){
			
			$delid		=	@implode(',',$_POST['del']);
			
			$layer_type	=	1;
		}else{
			$this -> check_token();
			
			$delid		=	(int)$_GET['id'];
			
			$layer_type	=	0;
		}
		
		$where['id']	=	array('in',$delid);
		
		$del	=	$chatM -> delChatLog(array('where'=>$where));
		
		$del?$this -> layer_msg('聊天记录(ID:'.$delid.')删除成功！',9,$layer_type,$_SERVER['HTTP_REFERER']):$this -> layer_msg('删除失败！',8,$layer_type,$_SERVER['HTTP_REFERER']);
		
	}
	function clean_action(){
		$month	=	intval($_POST['month']);
		
		$chatM	=	$this -> MODEL('chat');
		
		$where['sendTime']	=	array('<',strtotime("-".$month." month")*1000);
		
		$del	=	$chatM -> delChatLog(array('where'=>$where));
		
		$del?$this -> layer_msg('聊天记录清理成功！',9):$this -> layer_msg('清理失败！',8);
	}
}

?>